package  
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.ui.Mouse;
	
	/**
	 * ...
	 * @author hbb
	 */
	[SWF(width = "1280", height = "720", backgroundColor = "#999999", frameRate = "24")]
	public class CustomCursorDemo extends AbstractDemo 
	{
		
		override protected function init():void 
		{
			var x:Number = 50;
			var y:Number = 50;
			var hgap:Number = 350;
			var vgap:Number = 300;
			createArea(CursorManager.ARROW,  x,            y       );
			createArea(CursorManager.AUTO,   x + hgap,     y       );
			createArea(CursorManager.BUTTON, x + hgap * 2, y       );
			createText(500, y + vgap - 80);
			createArea(CursorManager.DICE,   x,            y + vgap);
			createArea(CursorManager.HAND,   x + hgap,     y + vgap);
			createArea(CursorManager.IBEAM,  x + hgap * 2, y + vgap);
			
			addEventListener(MouseEvent.MOUSE_OVER, onOver);
		}
		
		private function onOver(e:MouseEvent):void 
		{
			log('target:'+e.target.name, true);
			try{
				Mouse.cursor = e.target.name;
				log('cursor:' + Mouse.cursor);
			}catch (er:Error) {
				log('error:' +  er.message);
			}
		}
		
		private function log(msg:String, clear:Boolean = false):void
		{
			if (clear) TextField(getChildByName('logTxt')).text = '';
			TextField(getChildByName('logTxt')).appendText(msg + '\n');
		}
		
		private function createText(x:Number, y:Number):TextField
		{
			var tf:TextField = new TextField();
			tf.name = 'logTxt';
			tf.text = '';
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.width = 200;
			tf.height = 50;
			tf.x = x;
			tf.y = y;
			addChild(tf);
			return tf;
		}
		
		private function createArea(name:String, x:Number, y:Number):Sprite
		{
			var cont:Sprite = new Sprite();
			
			var border:Shape = new Shape();
			border.graphics.clear();
			border.graphics.beginFill(0xefefef);
			border.graphics.drawRoundRect(0, 0, 320, 180, 8, 8);
			border.graphics.endFill();
			
			var tf:TextField = new TextField();
			tf.name = name + '_txt';
			tf.text = name.toUpperCase();
			tf.multiline = false;
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.x = (border.width - tf.width) * .5;
			tf.y = (border.height - tf.height ) * .5;
			
			cont.addChild(border);
			cont.addChild(tf);
			cont.name = name;
			cont.filters = [ new DropShadowFilter(4, 60, 0x0, 1, 8, 8) ];
			cont.x = x;
			cont.y = y;
			//cont.mouseChildren = false;
			addChild(cont);
			
			return cont;
		}
		
	}

}